package ywh.ui
{
	import com.yahoo.astra.fl.controls.treeClasses.BranchNode;
	import com.yahoo.astra.fl.controls.treeClasses.TreeDataProvider;
	
	/**
	 * ...
	 * @author 杨伟华
	 */
	public class TreeMenuDataProvider extends TreeDataProvider
	{
		private var orderLabelName:String = "@orderLabel";
		
		public function TreeMenuDataProvider(data:Object)
		{
			super(data);
		}
		
		override protected function getDataFromObject(obj:Object):Array
		{
			if (obj is XML)
			{
				setOrderLabel(obj as XML)
			}
			return super.getDataFromObject(obj);
		}
		
		private function setOrderLabel(data:XML):void
		{
			var index:int = data.children().length() - 1;
			var xml:XML = data.*[index];
			var xmlp:XML;
			var indexp:int;
			while (xml)
			{
				var parentOLable:String = (xml.parent() && xml.parent().hasOwnProperty(orderLabelName)) ? xml.parent()[orderLabelName] + "." : "";
				xml[orderLabelName] = parentOLable + (index+1);
				if (xml.children().length() > 0)
				{
					index = xml.children().length() - 1;
					xml = xml.*[index];
				}
				else if (index > 0)
				{
					xml = xml.parent().children()[--index];
				}
				else
				{
					xmlp = xml.parent();
					do
					{
						indexp = xmlp.childIndex() - 1;
						xmlp = xmlp.parent();
					} while (indexp < 0 && xmlp);
					xml = (indexp < 0) ? null : xmlp.children()[indexp];
					index = indexp;
				}
			}
		}
	}

}